<template>
  <div v-if="model">
    <div class="topbar topbar-hero bg-black py-2 px-3 d-flex ai-center text-white">
      <img src="../assets/logo.png" height="26" />
      <div class="px-2 flex-1 fs-sm">
        <span class="text-white">王者荣耀</span>
        <span class="ml-2">攻略站</span>
      </div>
      <router-link
        to="/"
        tag="div"
        class="fs-sm mr-1 flex-grow-1"
        style="text-align: right;"
      >更多英雄 &gt;</router-link>
    </div>
    <div class="top" :style="{'background-image': `url(${model.bgc})`}">
      <div class="info text-white p-3 h-100 d-flex flex-column jc-end">
        <div class="fs-sm">{{model.title}}</div>
        <h2 class="my-1 fs-lg" style="font-weight:bold">{{model.name}}</h2>
        <div class="fs-sm">{{model.categories}}</div>
        <div class="d-flex jc-between pt-1 mb-4">
          <div class="scores d-flex ai-center fs-sm" v-if="model.score">
            <span>难度</span>
            <span class="badge bg-primary fs-sm">{{model.score.difficult}}</span>
            <span>技能</span>
            <span class="badge bg-blue-1 fs-sm">{{model.score.skills}}</span>
            <span>攻击</span>
            <span class="badge bg-danger fs-sm">{{model.score.attack}}</span>
            <span>生存</span>
            <span class="badge bg-dark fs-sm">{{model.score.survival}}</span>
          </div>
          <router-link to="/" tag="span" class="text-grey fs-sm">皮肤: 2 &gt;</router-link>
        </div>
      </div>
    </div>
    <!-- end of top -->
    <div>
      <div class="bg-white px-3">
        <div class="nav d-flex jc-around pt-3 pb-2 border-bottom">
          <div class="nav-item active">
            <div class="nav-link fs-sm">英雄初识</div>
          </div>
          <div class="nav-item">
            <div class="nav-link fs-sm">进阶攻略</div>
          </div>
        </div>
      </div>
      <swiper>
        <swiper-slide>
          <div>
            <div class="p-3 bg-white border-bottom">
              <div class="d-flex">
                <router-link tag="button" to="/" class="btn btn-lg flex-grow-1">
                  <i class="iconfont icon-menu1"></i>
                  英雄介绍视频
                </router-link>
                <router-link tag="button" to="/" class="btn btn-lg flex-grow-1 ml-2">
                  <i class="iconfont icon-menu1"></i>
                  一图识英雄
                </router-link>
              </div>

              <!-- skills -->
              <div class="skills bg-white mt-4">
                <div class="d-flex jc-around">
                  <img
                    class="icon"
                    @click="currentSkillIndex = i"
                    :class="{active: currentSkillIndex === i}"
                    :src="item.icon"
                    v-for="(item, i) in model.skills"
                    :key="item.name"
                  />
                </div>
                <div v-if="currentSkill">
                  <div class="d-flex pt-4 pb-3 fs-sm">
                    <h3
                      class="m-0"
                      style="font-size:0.128rem;font-weight:bold"
                    >{{currentSkill.name}}</h3>
                    <span class="text-grey-1 ml-4">
                      (冷却值: {{currentSkill.delay}}
                      消耗: {{currentSkill.cost}})
                    </span>
                  </div>
                  <p class="fs-sm">{{currentSkill.description}}</p>
                  <div class="border-bottom"></div>
                  <p class="text-grey-1 fs-sm">{{currentSkill.tips}}</p>
                </div>
              </div>
            </div>

            <m-card plain icon="menu" title="出装推荐" class="hero-items">
              <div class="fs-xl">顺风出装</div>
              <div class="d-flex jc-around text-center mt-3">
                <div v-for="item in model.items" :key="item.name">
                  <img :src="item.icon" class="icon" />
                  <div class="fs-xs pt-2">{{item.name}}</div>
                </div>
              </div>
              <div class="border-bottom mt-3"></div>
            </m-card>
            <m-card plain icon="menu" title="使用技巧">
              <p class="m-0 fs-sm">{{model.usageTips}}</p>
            </m-card>
            <m-card plain icon="menu" title="对抗技巧">
              <p class="m-0 fs-sm">{{model.battleTips}}</p>
            </m-card>
            <m-card plain icon="menu" title="团战思路">
              <p class="m-0 fs-sm">{{model.teamTips}}</p>
            </m-card>
          </div>
        </swiper-slide>
        <swiper-slide></swiper-slide>
      </swiper>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    id: { required: true }
  },
  data() {
    return {
      model: [],
      currentSkillIndex: 0
    };
  },
  computed: {
    currentSkill() {
      try {
        return this.model.skills[this.currentSkillIndex];
      } catch (err) {
        console.log("加载成功");
      }
    }
  },
  methods: {
    async fetchHeroDetails() {
      const res = await this.$http.get(`heros/Details/${this.id}`);
      let categories = res.data.data.seclists.map(v => v.name).join("/");
      this.model = res.data.data;
      this.$set(this.model, "categories", categories);
      this.$set(this.model, "usageTips",res.data.data.tip.usageTips);
      this.$set(this.model, "battleTips",res.data.data.tip.battleTips);
      this.$set(this.model, "teamTips",res.data.data.tip.teamTips);
      delete this.model.tip
    }
  },
  created() {
    this.fetchHeroDetails();
  }
};
</script>

<style lang="scss">
@import "../assets/_variables.scss";
.topbar-hero {
  height: 0.24rem;
}
.top {
  height: 50vw;
  background: #fff no-repeat top center;
  background-size: auto 100%;
}
.info {
  background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 1));
  .scores {
    .badge {
      margin: 0 0.05rem;
      height: 0.1rem;
      width: 0.1rem;
      line-height: 0.1rem;
      display: inline-block;
      text-align: center;
      border-radius: 50%;
      border: 1px solid rgba(255, 255, 255, 0.2);
    }
  }
}
.skills {
  img.icon {
    width: 50px;
    height: 50px;
    border: 3px solid map-get($colors, "white");
    &.active {
      border-color: map-get($colors, "primary");
    }
    border-radius: 50%;
  }
}
.hero-items {
  img.icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
</style>